cmake_minimum_required(VERSION 3.14)
project(agv_module LANGUAGES CXX C)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(Qt5_DIR $ENV{HOME}/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5)
message(STATUS ${Qt5_DIR})
find_package(Qt5 COMPONENTS
    Core Widgets Sql Network 
REQUIRED)

# fmt library
# set(fmt_DIR ${PROJECT_SOURCE_DIR}/third_party/fmt/lib/cmake/fmt)
# find_package(fmt REQUIRED)
add_subdirectory(third_party/fmtlib)
target_compile_options(fmt PRIVATE -fPIC -Wno-error=stringop-overflow -Wno-stringop-overflow) # gcc bug with fmtlib

# meojson
# add_subdirectory(third_party/meojson) # need cmake 3.19
include_directories(third_party/meojson/include/)

# spdlog
add_subdirectory(third_party/spdlog)
target_compile_options(spdlog PRIVATE -fPIC)

find_package(PCL REQUIRED)
find_package(OpenCV 4 REQUIRED)
find_package(Armadillo REQUIRED)
# find_package(mlpack REQUIRED)
find_package(Eigen3 REQUIRED)

include_directories(
/usr/local/include/vtk-8.2
${OPENCV_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${ARMADILLO_INCLUDE_DIRS}
# ${MLPACK_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)

link_directories(
${PCL_LIBRARY_DIRS}
${OpenCV_LIBS}
)

include_directories(third_party/Visual_PnP_Navigation/include)
file(GLOB_RECURSE AGVSRC third_party/Visual_PnP_Navigation/src/*.cpp)
file(GLOB_RECURSE AGVINC third_party/Visual_PnP_Navigation/include/*.h)

message(STATUS ${AGVSRC})

add_executable(agv_module_app 
    third_party/mtcp-read-write/src/MTcpClient.cpp
    third_party/mtcp-read-write/src/MTcpClient.h
    third_party/mtcp-read-write/src/MTcpServer.cpp
    third_party/mtcp-read-write/src/MTcpServer.h
    third_party/mtcp-read-write/src/MCrc.cpp
    third_party/mtcp-read-write/src/MCrc.h
    third_party/mtcp-read-write/src/MTcpFrame.cpp
    third_party/mtcp-read-write/src/MTcpFrame.h
    third_party/mtcp-read-write/src/MTcpReadWriteController.cpp
    third_party/mtcp-read-write/src/MTcpReadWriteController.h

    third_party/agv_imu_requester/AGVRequester.cpp
    third_party/agv_imu_requester/AGVRequester.h
    third_party/agv_imu_requester/AGVFrameHelper.cpp
    third_party/agv_imu_requester/AGVFrameHelper.h
    third_party/agv_imu_requester/agv_header.h

    ${AGVSRC}
    ${AGVINC}

    src/main.cpp
    src/mainwindow.cpp
    src/mainwindow.h
    src/mainwindow.ui
    src/agvmodule_defines.h
    src/AGVThreadController.cpp
    src/AGVThreadController.h
    src/log.h
    src/LogListPanel/LogListPanel.cpp
    src/LogListPanel/LogListPanel.h
    src/LogListPanel/LogListPanel.ui
    src/TestPicShowWidget.cpp
    src/TestPicShowWidget.h
    src/TestPicShowWidget.ui
    src/CustomEvent.h
)


add_definitions(-DAGV_ROOT_DIR="${PROJECT_SOURCE_DIR}/third_party/Visual_PnP_Navigation/")
add_definitions(-DROOT_DIR="${PROJECT_SOURCE_DIR}/")
add_definitions(-DDISABLE_AGV_WINDOWSHOW)
# add_definitions(-DDISABLE_AGV_STDOUT)
target_compile_options(agv_module_app PUBLIC -fPIC -Wno-error=stringop-overflow -Wno-stringop-overflow) # gcc bug with fmtlib

target_link_libraries(agv_module_app PUBLIC
    Qt5::Core
    Qt5::Network
    Qt5::Widgets
    ${PCL_LIBRARIES}
    ${OpenCV_LIBS}
    ${ARMADILLO_LIBRARIES}
    spdlog::spdlog
    fmt::fmt
)

# 添加一个自定义目标，该目标在构建时执行 scripts/run.sh 脚本
add_custom_target(RunScript ALL
    COMMAND ${CMAKE_COMMAND} -E echo "Running generate_desktop.sh script..."
    COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_SOURCE_DIR}/scripts/generate_desktop.sh
    COMMENT "Executing run.sh script"
    VERBATIM  # 如果脚本路径或参数中包含空格，则使用此选项
)